package cn.xxi.ai.application.dto;

import cn.xxi.ai.util.MapCleaner;
import lombok.Getter;

import java.util.Map;

@Getter
public class WorkflowStarted extends StartedEvent<Map<String, Object>> {

    /** 工作流 ID */
    private final Long workflowId;

    /** 输入 */
    private final Map<String, Object> inputs;

    public WorkflowStarted(Long workflowId, Map<String, Object> inputs) {
        this.workflowId = workflowId;
        this.inputs = inputs;
    }

    @Override
    public FinishedEvent toSuccessEvent(Map<String, Object> outputs) {
        return new WorkflowFinished(workflowId, inputs, MapCleaner.clean(outputs), Status.SUCCESS, null, startedAt);
    }

    @Override
    public FinishedEvent toFailureEvent(String error) {
        return new WorkflowFinished(workflowId, inputs, Map.of(), Status.FAILURE, error, startedAt);
    }
}
